from sanic import Sanic
from db_connect import ConnMysql
from db_connect import ConnRedis
from db_connect import ConnMysqlSlave

from api_order import bp_apiorder
from product_type import bp_product_type

from product_add_api import bp_product
from api_order_status import bp_apiorderstatus
from api_product import bp_product_app

app = Sanic("App Name")

#配置项目静态文件夹地址
app.static('/static', './static')

app.blueprint(bp_apiorder)

app.blueprint(bp_product_type)
app.blueprint(bp_product)
app.blueprint(bp_apiorderstatus)
app.blueprint(bp_product_app)

@app.listener('after_server_start')
async def notify_server_started(app, loop):
    ConnMysql(loop=loop)
    ConnRedis(loop=loop)
    ConnMysqlSlave(loop=loop)
    print('Server MySql and Redis successfully started!')


if __name__ == "__main__":

    app.run(port=8000, debug=True)